#include "changesettings.h"

#include <QStringList>
#include <QDebug>



/**
 * 由于Python C API和QProcess之间的python解释器之间的冲突，这段代
 * 码暂时弃用，即取消通过多线程来调用QProcess而是直接采取混合编程的方式。
 */



ChangeSettings::ChangeSettings(QObject *parent) : QObject(parent)
{
    process = new QProcess(this);
}

ChangeSettings::~ChangeSettings()
{
    process->close();
    delete process;
}

void ChangeSettings::change_rate(int rate)
{
    try {
            QString pythonpath = PYTHONS;
            process->start(pythonpath, QStringList() << SCRIPTS << "rate" << QString::number(rate));
            process->waitForFinished();
        } catch (const QString& errorMsg) {
            qDebug() << errorMsg;
    }
}

void ChangeSettings::change_pitch(int pitch)
{
    try {
            QString pythonpath = PYTHONS;
            process->start(pythonpath, QStringList() << SCRIPTS << "pitch" << QString::number(pitch));
            process->waitForFinished();
        } catch (const QString& errorMsg) {
            qDebug() << errorMsg;
    }
}

void ChangeSettings::change_voice(int voice)
{
    try {
            QString pythonpath = PYTHONS;
            process->start(pythonpath, QStringList() << SCRIPTS << "voice" << QString::number(voice));
            process->waitForFinished();
        } catch (const QString& errorMsg) {
            qDebug() << errorMsg;
    }
}
